﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.JSDWF
{
    public partial class JSUserDWFApplyFolderList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "JSUserDWFApplyList";
            }
        }
        #region 属性 (查询条件)


        protected string FileName
        {
            get
            {
                return GetRequestValue<string>("FileName", "");

            }
        }

        protected int FolderID
        {
            get
            {
                return GetRequestValue<int>("FolderID", 0);
            }
        }


        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "FolderID" : base.orderField;
            }
        }
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }


        #endregion
        protected string AdtlvlName(object _adtlvid)
        {
            int parFolderID = Convert.ToInt32(_adtlvid);
            SAuditLevelInfo parobj = SAuditLevelController.GetAditlvlById(SAuditLevelType.DWF, parFolderID);
            //if (parobj == null)
            //    return "";
            //else
            //    return parobj.Title;

            string html = "<b style='color:{0}'>{1}</b>";
            switch (parobj.AdtlvlID)
            {
                case 1:
                    html = string.Format(html, "#000", parobj.Title);
                    break;
                case 2:
                    html = string.Format(html, "green", parobj.Title);
                    break;
                case 3:
                    html = string.Format(html, "#EB5EE6", parobj.Title);
                    break;
                case 4:
                    html = string.Format(html, "red", parobj.Title);
                    break;
                default:
                    html = string.Format(html, "#000", parobj.Title);
                    break;
            }
            return html;


        }
        protected string ParFolderName(object _ParFolderID)
        {
            int parFolderID = Convert.ToInt32(_ParFolderID);
            JSDWFFolderInfo parobj = JSDWFFolderController.GetByFolderID(parFolderID);
            if (parobj == null)
                return "图纸根目录";
            else
                return parobj.FolderName;

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            this.AddLog(Permission.查看, GetSql());
        }

        protected void DataBind()
        {

            this.rpMenu.DataSource = JSDWFController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }
        protected string GetSql()
        {
            string wheresql = "";

            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(FileName))
            {
                ItemCodeSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("FileName", QueryOperatorsEnum.包含, FileName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            string DOWNSQL = "";
            if (FolderID > 0)
            {
                DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("FolderID", QueryOperatorsEnum.等于, FolderID.ToString());
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }


            return wheresql;
        }


        /// <summary>
        /// 获取相应的图纸，当前用户的操作权限
        /// 要么可以查看，要么只能先申请
        /// </summary>
        /// <param name="DWFID"></param>
        /// <returns></returns>
        protected string GetListItemRight(object _DWFID, object FileName, object _AdtlvlID)
        {
            Guid DWFID = new Guid(_DWFID.ToString());
            //是否在申请判
            List<JSDWFApplyDetailInfo> applydetailList = JSDWFApplyController.GetDWFApplyByUserName(base.User.UserName);
            if (applydetailList != null)
            {
                JSDWFApplyDetailInfo obj = applydetailList.Find(e => e.DWFID == DWFID);
                if (obj != null)
                    return "<b style='color:Lime;'>正在审批</b>";
            }
            //权限判断
            List<JSUserDWFInfo> userDwfList= JSUserDWFController.GetListByUserName(base.User.UserName);
            if (userDwfList != null)
            {
                JSUserDWFInfo rightObj = userDwfList.Find(e => e.DWFID == DWFID);
                if (rightObj == null)
                {
                    //没权限
                    return string.Format("<a onclick=\"JSUserDWFApplySelect_OnClick('{0}','{1}','{2}')\" style=\"color:red\">申请</a>", DWFID, FileName, _AdtlvlID);
                }
                else
                {
                    return string.Format("<a  title=\"点击可查看图纸\" href=\"JSDWF/JSUserDWFView.aspx?DWFID={0}\" target=\"ajax\" rel=\"JSUserDWFApplyListViewjbsxBox\" style=\"color:Green\" >查看</a>", DWFID);
                }
            }
            else
            {
                return string.Format("<a onclick=\"JSUserDWFApplySelect_OnClick('{0}','{1}','{2}')\" style=\"color:red\">申请</a>", DWFID, FileName, _AdtlvlID);
            }

        }
    }
}